package com.twu.biblioteca.ui.menus.items.books;

import com.twu.biblioteca.library.Library;
import com.twu.biblioteca.ui.menus.AbstractMenu;
import com.twu.biblioteca.ui.menus.books.NoReturnBooksMenu;
import com.twu.biblioteca.ui.menus.books.ReturnBookMenu;
import com.twu.biblioteca.ui.menus.items.AbstractMenuItem;
import com.twu.biblioteca.users.User;
import com.twu.biblioteca.users.UserAccountsManager;

/**
 * @author Alvi Jonathan Sait
 */
public class ReturnBookMenuItem extends AbstractMenuItem {

    public ReturnBookMenuItem() {
        super("Return Book");
    }

    @Override
    public AbstractMenu handleAction(Library library) {
        User user = library.getUserAccountsManager().getCurrentlyActiveUser().get();
        if (user.getBooks().isEmpty()) {
            return new NoReturnBooksMenu(library);
        }
        return new ReturnBookMenu(library);
    }

    /**
     * This menu item is only available if there is a logged-in user.
     */
    @Override
    public boolean isViewableByActiveUser(UserAccountsManager userAccountsManager) {
        return userAccountsManager.getCurrentlyActiveUser().isPresent();
    }
}
